<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Model as BaseModel;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

class AgentModel extends BaseModel
{
    use HasFactory, SoftDeletes;

    protected $table = 't_agent';

    protected $primaryKey = 'id';

    public $timestamps = true;

    const CREATED_AT = 'created_at';
    
    const UPDATED_AT = null;

    protected $guarded = [];

    protected $hidden = [
        'deleted_at',
    ];

    //代理类型 1航司运输 2一般贸易 3单独报关 4清关 5机场操作 6港车 7打单 8打板 9提货送货
    const AGENT_TYPE_AIRLINE = 1; //航司运输
    const AGENT_TYPE_YMB = 2;  //一般贸易
    const AGENT_TYPE_BG = 3;  //单独报关
    const AGENT_TYPE_QG = 4;  //清关
    const AGENT_TYPE_AP = 5;  //机舱操作
    const AGENT_TYPE_HG = 6;  //港车
    const AGENT_TYPE_DD = 7;  //打单
    const AGENT_TYPE_DB = 8;  //打版
    const AGENT_TYPE_TH = 9;  //提货送货
    const TYPE_LIST = [
        self::AGENT_TYPE_AIRLINE => '航司运输',
        self::AGENT_TYPE_YMB => '一般贸易',
        self::AGENT_TYPE_BG => '报关',
        self::AGENT_TYPE_QG => '清关',
        self::AGENT_TYPE_AP => '机舱操作',
        self::AGENT_TYPE_HG => '港车',
        self::AGENT_TYPE_DD => '打单',
        self::AGENT_TYPE_DB => '打版',
        self::AGENT_TYPE_TH => '提货送货',
    ];

    //创建人
    public function create_admin(): BelongsTo {
        return $this->belongsTo(AdminModel::class, 'created_admin_id');
    }

    //收费设置
    public function cost(): HasMany {
        return $this->hasMany(AgentCostModel::class, 'agent_id');
    }

}
